
use ../Intermediate/borrowing_panel, clear

//get betas for different time periods and different condings of debt
gen pos_borr = borr_debt > 0
gen log1pdebt = log(1+borr_debt)
gen logdebt = log(borr_debt)


tempfile betasl1p 
statsby _b , by(borrower_id) saving(`betasl1p'): reg log1pdebt year if inrange(year,2005,2013)
tempfile betaspos
statsby _b , by(borrower_id) saving(`betaspos'): reg pos_borr year if inrange(year,2005,2013)
tempfile beta0913
statsby _b , by(borrower_id) saving(`beta0913'): reg log1pdebt year if inrange(year,2009,2013)


//look at debt growth 2005-2009 vs 2010-2013
egen borr_debt_0509 = total(borr_debt*inrange(year,2005,2009)), by(borrower_id)
egen borr_debt_1013 = total(borr_debt*inrange(year,2010,2013)), by(borrower_id)

keep borrower_id borr_debt_0509 borr_debt_1013
duplicates drop
merge 1:1 borrower_id using `betasl1p', nogen
rename _b* _b*_l1p
merge 1:1 borrower_id using `betaspos', nogen
rename _b_year _b_year_pd
rename _b_cons _b_cons_pd
merge 1:1 borrower_id using `beta0913', nogen
rename _b_year _b_year_0913
rename _b_cons _b_cons_0913
gen pre_growth = borr_debt_1013/borr_debt_0509-1
gen log_pre_growth = log(1+borr_debt_1013)-log(1+borr_debt_0509)
rename pre_growth pre_growth_borr
rename log_pre_growth log_pre_growth_borr

save ../Intermediate/borrower_pretrends, replace
